﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using W_Fish.Models;

namespace W_Fish.Controllers
{
    public class UserController : Controller
    {
        //
        // GET: /User/
        int Max = 1000000;
        FishManagement_Timkiem db = new FishManagement_Timkiem();
        #region[List]


        public ActionResult List()
        {
            string chuoi = "";

            var ca = (from x in db.Fish select x).ToList<Fish>();

            for (int i = 0; i < ca.Count; i++)
            {
                chuoi += "<tr>";
                chuoi += "<td align=\"left\" width=\" 100px\" height=\"100px\">";
                chuoi += "<img src=\"" + ca[i].image + "\"/>";
                chuoi += "</td>";
                chuoi += "<td width=\"20px\"></td><td width=\"800px\"> <table><tr>";
                chuoi += ca[i].FishName + " " + ca[i].Growth;
                chuoi += "</p></tr><tr>";
                chuoi += "<td align=\"center\"> <a href = \"/User/Information?id_fish=" + ca[i].FishID + " \"> Xem thêm </a></td>";
                chuoi += "</tr>";
                chuoi += " </table>";
                chuoi += "</td>";
                chuoi += "</tr>";

            }
            ViewBag.View = chuoi;

            return View();
        }
        #endregion
        #region[ListPhylum]
        public ActionResult ListPhylum(int id_phylum)
        {
            var Phy = (from _phy in db.Phyla where _phy.PhylumID == id_phylum && _phy.Ph_kiemduyet==true select _phy).ToList<Phylum>();
            var Cl = (from _cl in db.ClassFish where _cl.IdPh == id_phylum && _cl.Cl_kiemduyet== true select _cl).ToList<ClassFish>();
            ViewBag.PhylumName = Phy.First().PhylumName;
            ViewBag.SH= Phy.First().PhylumBiology;
            ViewBag.live = Phy.First().PhylumHabitat;
            string chuoi= "";
            int i= 1;
            foreach (ClassFish mem in Cl)
            {
                chuoi += "<a href=\"/User/ListClass?id_class= " + mem.ClassID + "\">" + i + ". " + mem.ClassName + " </a> <br />";
                i = i + 1;
            }

            ViewBag.ListClass = chuoi;
            return View();
       
        }
        #endregion
        #region[ListClass]
        public ActionResult ListClass(int id_class)
        {
            var Cls = (from _cls in db.ClassFish where _cls.ClassID == id_class && _cls.Cl_kiemduyet == true select _cls).ToList<ClassFish>();
            var Or = (from _or in db.Ordoes where _or.ClassID == id_class && _or.Or_kiemduyet == true select _or).ToList<Ordo>();
            ViewBag.ClassName = Cls.First().ClassName;
            ViewBag.SH = Cls.First().ClassBiology;
            ViewBag.live = Cls.First().ClassHabitat;
            string chuoi = "";
            int i = 1;
            foreach (Ordo mem in Or)
            {
                chuoi += "<a href=\"/User/ListOrdo?id_ordo= " + mem.OrdoID + "\">" + i + ". " + mem.OrdoName + " </a> <br />";
                i = i + 1;
            }

            ViewBag.ListOrdo = chuoi;
            return View();
        }
        #endregion
        #region[ListOrdo]
        public ActionResult ListOrdo(int id_ordo)
        {
            var Or = (from _or in db.Ordoes where _or.OrdoID == id_ordo && _or.Or_kiemduyet == true select _or).ToList<Ordo>();
            var Fa = (from _fa in db.Familias where _fa.OrdoID == id_ordo && _fa.Fa_kiemduyet == true select _fa).ToList<Familia>();
            ViewBag.ClassName = Or.First().OrdoName;
            ViewBag.SH = Or.First().OrdoBiology;
            ViewBag.live = Or.First().OrdoHabitat;
            string chuoi = "";
            int i = 1;
            foreach (Familia mem in Fa)
            {
                chuoi += "<a href=\"/User/ListFamily?id_family= " + mem.FamiliaID + "\">" + i + ". " + mem.FamilialName + " </a> <br />";
                i = i + 1;
            }

            ViewBag.ListFamily = chuoi;
            return View();
        }

        #endregion
        #region[Listfamily]
        public ActionResult ListFamily(int id_family)
        {
            var Fa = (from _fa in db.Familias where _fa.FamiliaID == id_family && _fa.Fa_kiemduyet == true select _fa).ToList<Familia>();
            var Ge = (from _ge in db.Genus where _ge.FamiliaID == id_family && _ge.Ge_kiemduyet == true select _ge).ToList<Genu>();
            ViewBag.ClassName = Fa.First().FamilialName;
            ViewBag.SH = Fa.First().FamilialBiology;
            ViewBag.live = Fa.First().FamilialHabitat;
            string chuoi = "";
            int i = 1;
            foreach (Genu mem in Ge)
            {
                chuoi += "<a href=\"/User/ListGenus?id_genus= " + mem.GenusID + "\">" + i + ". " + mem.GenusName + " </a> <br />";
                i = i + 1;
            }

            ViewBag.ListGenus = chuoi;
            return View();            
        }
        #endregion
        #region[ListGenus]
        public ActionResult ListGenus(int id_genus)
        {
            var Ge = (from _ge in db.Genus where _ge.GenusID == id_genus && _ge.Ge_kiemduyet == true select _ge).ToList<Genu>();
            var Fi = (from _fi in db.Fish where _fi.GenusID == id_genus && _fi.Fi_kiemduyet == true select _fi).ToList<Fish>();
            ViewBag.ClassName = Ge.First().GenusName;
            ViewBag.SH = Ge.First().GenusBiology;
            ViewBag.live = Ge.First().GenusHabitat;
            string chuoi = "";
            int i = 1;
            foreach (Fish mem in Fi)
            {
                chuoi += "<a href=\"/User/Information?id_fish=" + mem.FishID + "\">" + i + ". " + mem.FishName + " </a> <br />";
                i = i + 1;
            }

            ViewBag.ListFish = chuoi;
            return View();
        }
        #endregion
        #region[Info]
        public ActionResult Information(int id_fish)
        {

            string a = "";
            var info = (from tt in db.Fish where tt.FishID == id_fish && tt.Fi_kiemduyet == true select tt);

            Fish cur = new Fish();
            cur = info.First();

            int Ge_ID = cur.GenusID;
            var ge = (from ttge in db.Genus where ttge.GenusID == Ge_ID && ttge.Ge_kiemduyet == true select ttge);

            int Fa_ID = ge.First().FamiliaID;
            var fa = (from ttfa in db.Familias where ttfa.FamiliaID == Fa_ID && ttfa.Fa_kiemduyet == true select ttfa);

            int Or_ID = fa.First().OrdoID;
            var or = (from ttor in db.Ordoes where ttor.OrdoID == Or_ID && ttor.Or_kiemduyet == true select ttor);

            int Cl_ID = or.First().ClassID;
            var cl = (from ttcl in db.ClassFish where ttcl.ClassID == Cl_ID && ttcl.Cl_kiemduyet == true select ttcl);


            ClassFish myclass = new ClassFish();
            myclass = cl.First();

            int Ph_ID = myclass.IdPh;

            var ph = (from ttph in db.Phyla where ttph.PhylumID == Ph_ID && ttph.Ph_kiemduyet == true select ttph);



           
         
            a += "<center>";
            a += "<img src=\"/Images/catroivn.png\" />";
            a += "<h3 style=\"color: #0033CC\">" + cur.FishName + "</h3>";
            a += "</center>";
            a += "<br />";
            a += "<a href = \"/User/ListPhylum?id_phylum=" + ph.First().PhylumID + "\"> Ngành " + ph.First().PhylumName + " </a>";
            a += "<br />";
            a += "<a href = \"/User/ListClass?id_class=" + cl.First().ClassID + "\"> Lớp " + cl.First().ClassName + " </a>";
            a += "<br />";
            a += "<a href = \"/User/ListOrdo?id_ordo=" + or.First().OrdoID + "\"> Bộ " + or.First().OrdoName + " </a>";
            a += "<br />";
            a += "<a href = \"/User/ListFamily?id_family=" + fa.First().FamiliaID + "\"> Họ " + fa.First().FamilialName + " </a>";
            a += "<br />";
            a += "<a href = \"/User/ListGenus?id_genus=" + ge.First().GenusID + "\"> Chi " + ge.First().GenusName + " </a>";
            a += "<br />";
            a += "<h4><i style=\"color: #990000\">1. Tên cá </i></h4>";
            a += "<p>";
            a += "•	Tên loài: " + cur.FishName ;
            a += "<br />";
            a += "•	Tên chính thức: " + cur.MainName;
            a += "<br />";
            a += "•	Tên danh pháp: " + cur.Nomerclature;
            a += "<br />";
            a += "•	Tên Việt Nam: " + cur.NameVN;
            a += "<br />";
            a += "</p>";
            a += "<h4><i style=\"color: #990000\">2. Phân bố </i></h4>";
            a += "<p>";
            a += "Trong nước:" + cur.FishHabitatVN;
            a += "<br />";
            a += "Thế giới:" + cur.FishHabittatW;
            a += "<br />";
            a += "</p>";
            a += "<h4><i style=\"color: #990000\">3. Mô tả hình thái và dữ liệu sinh học </i></h4>";
            a += "<p>";
            a += "Tập tính sống: " + cur.LivingHabit;
            a += "<br />";
            a += "Dinh dướng: " + cur.Nutrition;
            a += "<br />";
            a += "Sinh trưởng: " + cur.Growth;
            a += "<br />";
            a += "Sinh sản: " + cur.Reproduction;
            a += "<br />";
            a += "</p>";
            a += "<h4><i style=\"color: #990000\">4. Đặc điểm hình thái</i></h4>";
            a += "<p>";
            if (cur.LoH_Min < 0 && cur.LoH_Max < Max) { a += "•	*Lo/H: < " + cur.LoH_Max + " <br /> "; }
            if (cur.LoH_Min > 0 && cur.LoH_Max > Max) { a += "•	*Lo/H: >" + cur.LoH_Min +  " <br /> "; }
            if (cur.LoH_Min > 0 && cur.LoH_Max < Max) { a += "•	*Lo/H: " + cur.LoH_Min + " - " + cur.LoH_Max + " <br /> "; }
            if (cur.LoT_Min < 0 && cur.LoT_Max < Max) { a += "•	*Lo/T: <" + cur.LoT_Max + "<br /> "; }
            if (cur.LoT_Min > 0 && cur.LoT_Max > Max) { a += "•	*Lo/T: >" + cur.LoT_Min + "<br /> "; }
            if (cur.LoT_Min > 0 && cur.LoT_Max < Max) { a += "•	*Lo/T: " + cur.LoT_Min + " - " + cur.LoT_Max + "<br /> "; }

            if (cur.Lolcd_Min < 0 && cur.Lolcd_Max < Max) { a += "•	  Lo/lcd: <" + cur.Lolcd_Max + " <br /> "; }
            if (cur.Lolcd_Min > 0 && cur.Lolcd_Max > Max) { a += "•	  Lo/lcd: >" + cur.Lolcd_Min + " <br /> "; }
            if (cur.Lolcd_Min > 0 && cur.Lolcd_Max < Max) { a += "•	  Lo/lcd: " + cur.Lolcd_Min + " - " + cur.Lolcd_Max + " <br /> "; }
             
            if (cur.Loccd_Min < 0 && cur.Loccd_Max < Max) { a += "•	  Lo/ccd: <" + cur.Loccd_Max + " <br /> "; }
            if (cur.Loccd_Min > 0 && cur.Loccd_Max > Max) { a += "•	  Lo/ccd: >" + cur.Loccd_Min + " <br /> "; }
            if (cur.Loccd_Min > 0 && cur.Loccd_Max < Max) { a += "•	  Lo/ccd: " + cur.Loccd_Min + " - " + cur.Loccd_Max + " <br /> "; }

            if (cur.TOt_Min < 0 && cur.TOt_Max < Max) { a += "•	  T/Ot: <" + cur.TOt_Max + " <br /> "; }
            if (cur.TOt_Min > 0 && cur.TOt_Max > Max) { a += "•	  T/Ot: >" + cur.TOt_Min + " <br /> "; }
            if (cur.TOt_Min > 0 && cur.TOt_Max < Max) { a += "•	  T/Ot: " + cur.TOt_Min + " - " + cur.TOt_Max + " <br /> "; }

            if (cur.TO_Min < 0 && cur.TO_Max < Max) { a += "•	T/O: <" + cur.TO_Max + " <br /> "; }
            if (cur.TO_Min > 0 && cur.TO_Max > Max) { a += "•	T/O: >" + cur.TO_Min + " <br /> "; }
            if (cur.TO_Min > 0 && cur.TO_Max < Max) { a += "•	T/O: " + cur.TO_Min + " - " + cur.TO_Max + " <br /> "; }

            if (cur.TOO_Min < 0 && cur.TOO_Max < Max) { a += "•	  T/OO: <" + cur.TOO_Max + " <br /> "; }
            if (cur.TOO_Min > 0 && cur.TOO_Max > Max) { a += "•	  T/OO: >" + cur.TOO_Min + " <br /> "; }
            if (cur.TOO_Min > 0 && cur.TOO_Max < Max) { a += "•	  T/OO: " + cur.TOO_Min + " - " + cur.TOO_Max + " <br /> "; }

            if (cur.Tlcd_Min < 0 && cur.Tlcd_Max < Max) { a += "•	T/lcd: <" + cur.Tlcd_Max + " <br /> "; }
            if (cur.Tlcd_Min > 0 && cur.Tlcd_Max > Max) { a += "•	T/lcd: >" + cur.Tlcd_Min + " <br /> "; }
            if (cur.Tlcd_Min > 0 && cur.Tlcd_Max < Max) { a += "•	T/lcd: " + cur.Tlcd_Min + " - " + cur.Tlcd_Max + " <br /> "; }

            if (cur.Tccd_Min < 0 && cur.Tccd_Max < Max) { a += "•	T/ccd: <" + cur.Tccd_Max + " <br /> "; }
            if (cur.Tccd_Min > 0 && cur.Tccd_Max > Max) { a += "•	T/ccd: >" + cur.Tccd_Min + " <br /> "; }
            if (cur.Tccd_Min > 0 && cur.Tccd_Max < Max) { a += "•	T/ccd: " + cur.Tccd_Min + " - " + cur.Tccd_Max + " <br /> "; }

            if (cur.Hh_Min < 0 && cur.Hh_Max < Max) { a += "•   H/h: <" + cur.Hh_Max + " <br /> "; }
            if (cur.Hh_Min > 0 && cur.Hh_Max > Max) { a += "•	H/h: >" + cur.Hh_Min + " <br /> "; }
            if (cur.Hh_Min > 0 && cur.Hh_Max < Max) { a += "•	H/h: " + cur.Hh_Min + " - " + cur.Hh_Max + " <br /> "; }

            if (cur.OOO_Min < 0 && cur.OOO_Max < Max) { a += "•	  OO/O: <" + cur.OOO_Max + " <br /> "; }
            if (cur.OOO_Min > 0 && cur.OOO_Max > Max) { a += "•	  OO/O: >" + cur.OOO_Min+ " <br /> "; }
            if (cur.OOO_Min > 0 && cur.OOO_Max < Max) { a += "•	  OO/O: " + cur.OOO_Min + " - " + cur.OOO_Max + " <br /> "; }

            if (cur.lcdccd_Min < 0 && cur.lcdccd_Max < Max) { a += "•	lcd/ccd: <" + cur.lcdccd_Max + " <br /> "; }
            if (cur.lcdccd_Min > 0 && cur.lcdccd_Max > Max) { a += "•	lcd/ccd: >" + cur.lcdccd_Min + " <br /> "; }
            if (cur.lcdccd_Min > 0 && cur.lcdccd_Max < Max) { a += "•	lcd/ccd: " + cur.lcdccd_Min + " - " + cur.lcdccd_Max + " <br /> "; }
            
            if (cur.LcmaxLcmin_Min < 0 && cur.LcmaxLcmin_Max < Max) { a += "•	Lcmax/Lcmim: <" + cur.LcmaxLcmin_Max + " <br /> " ;}
            if (cur.LcmaxLcmin_Min > 0 && cur.LcmaxLcmin_Max > Max) { a += "•	Lcmax/Lcmim: >" + cur.LcmaxLcmin_Min + " <br /> " ;}
            if (cur.LcmaxLcmin_Min > 0 && cur.LcmaxLcmin_Max < Max) { a += "•	Lcmax/Lcmim: " + cur.LcmaxLcmin_Min + " - " + cur.LcmaxLcmin_Max + " <br /> "; }
            
            if (cur.LodaD_Min < 0 && cur.LodaD_Max < Max) { a += "•	  Lo/daD: <" + cur.LodaD_Max + " <br /> ";}
            if (cur.LodaD_Min > 0 && cur.LodaD_Max > Max) { a += "•	  Lo/daD: >" + cur.LodaD_Min + " <br /> ";}
            if (cur.LodaD_Min > 0 && cur.LodaD_Max < Max) { a += "•	  Lo/daD: " + cur.LodaD_Min + " - " + cur.LodaD_Max + " <br /> "; }
            
            if (cur.PVVA_Min < 0 && cur.PVVA_Max < Max) { a += "•	P-V/V-A: <" + cur.PVVA_Max + " <br /> "; }
            if (cur.PVVA_Min > 0 && cur.PVVA_Max > Max) { a += "•	P-V/V-A: >" + cur.PVVA_Min + " <br /> "; }
            if (cur.PVVA_Min > 0 && cur.PVVA_Max < Max) { a += "•	P-V/V-A: " + cur.PVVA_Min + " - " + cur.PVVA_Max + " <br /> "; }
            
            a += "</p>";
            a += "<h4><i style=\"color: #990000\">5. Giá trị sử dụng </i></h4>";
            a += "<p>";
            a += "Giá trị khoa học: " + cur.Scientific;
            a += "<br />";
            a += "Giá trị kinh tế: " + cur.Economic;
            a += "<br />";
            a += "Hiện trạng nguồn lợi: " + cur.Resourcce;
            a += "<br />";
            a += "</p>";
           
            ViewBag.tt = a;

            return View();
        }

        #endregion
        #region[UserByName]
        public ActionResult UserByName()
        {
            List<SelectListItem> dropdownItems = new List<SelectListItem>();
            dropdownItems.AddRange(new[]{
                            new SelectListItem() { Text = "Loài ", Value = "1" },
                            new SelectListItem() { Text = "Chi", Value = "2" },
                            new SelectListItem() { Text = "Họ", Value = "3" },
                            new SelectListItem() { Text= "Bộ", Value= "4"},
                            new SelectListItem() { Text= "Lớp", Value ="5"},
                            new SelectListItem() { Text = "Ngành", Value ="6"}});
            ViewData.Add("DropDownItems", dropdownItems);
            return View();
        }

        [HttpPost]
        public ActionResult UserByName(FormCollection collection)
        {
            string txtten = collection["tentimkiem"];
            int txtluachon = int.Parse(collection["luachon"]);
            if (txtten == null)
            {
                ViewBag.thongbao = "Mời nhập tên cần tìm kiếm";
                return View();
            }
            return RedirectToAction("Result", new { txtname = txtten, luachon = txtluachon });
        }

        #endregion
        #region[selectbystype]
        public ActionResult UserByStype()
        {
            return View();
        }
        
        [HttpPost]
        public ActionResult UserByStype(FormCollection collection)
        {
            double txtlo = double.Parse(collection["Lo"]);
            double txtH = double.Parse(collection["H"]);
            double txtt = double.Parse(collection["T"]);
            double txtlcd = double.Parse(collection["Lcd"]);
            double txtccd = double.Parse(collection["ccd"]);
            double txtot = double.Parse(collection["Ot"]);
            double txto = double.Parse(collection["O"]);
            double txtoo = double.Parse(collection["OO"]);
            double txth = double.Parse(collection["h"]);
            double txtlcmax = double.Parse(collection["Lc_max"]);
            double txtlcmin = double.Parse(collection["Lc_min"]);
            double txtdaD = double.Parse(collection["daD"]);
            double txtPV = double.Parse(collection["P-V"]);
            double txtVA = double.Parse(collection["V-A"]);

            Tile a = new Tile();

            try { a.Hh = txtH / txth; }
            catch { a.Hh = 0; }
            try { a.lcdccd = txtlcd / txtccd; }
            catch { a.lcdccd = 0; }
            try { a.LcmaxLcmin = txtlcmax / txtlcmin; }
            catch { a.LcmaxLcmin = 0; }
            try { a.Loccd = txtlo / txtccd; }
            catch { a.Loccd = 0; }
            try { a.LodaD = txtlo / txtdaD; }
            catch { a.LodaD = 0; }
            try { a.OOO = txto / txtoo; }
            catch { a.OOO = 0; }
            try { a.PVVA = txtPV / txtVA; }
            catch { a.PVVA = 0; }
            try { a.Tccd = txtt / txtccd; }
            catch { a.Tccd = 0; }
            try { a.Tlcd = txtt / txtlcd; }
            catch { a.Tlcd = 0; }
            try { a.TO = txtt / txto; }
            catch { a.TO = 0; }
            try { a.TOO = txtt / txtoo; }
            catch { a.TOO = 0; }

            return RedirectToAction("ResultStype", new { tl = txtH });
        }

     

        #endregion
        #region[ResultStype]
        public ActionResult ResultStype( double tl)
        {
            string sodo= "";
            sodo ="du nay la dc rui day" + tl ;
            ViewBag.sodo = sodo;//Viết lệnh truy vấn vào đây!
            
            return View();
        }
        #endregion  
        #region[Result]
        public ActionResult Result(string txtname, int luachon)
        {
            
            List<Fish> ds = new List<Fish>();
            
            switch (luachon)
            {
                case 1:
                    {
                        ds = (from a in db.Fish where a.FishName == txtname && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                        break;
                    }
                case 2:
                    {
                        List<Fish> curf;
                        List<int> chi = (from b in db.Genus where b.Ge_kiemduyet == true && b.GenusName == txtname select b.GenusID).ToList<int>();
                        foreach (int i in chi)
                        {
                            curf = new List<Fish>();
                            curf = (from a in db.Fish where a.GenusID == i && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                            foreach (Fish x in curf)
                            {
                                ds.Add(x);
                            }
                        }
                        break;
                    }
                case 3:
                    {
                        List<Fish> curf;
                        List<int> ho = (from h in db.Familias where h.FamilialName == txtname && h.Fa_kiemduyet == true select h.FamiliaID).ToList<int>();
                        foreach (int i in ho)
                        {
                            var chi = (from c in db.Genus where c.FamiliaID == i && c.Ge_kiemduyet == true select c.GenusID).ToList<int>();
                            foreach (int curc in chi)
                            {
                                curf = new List<Fish>();
                                curf = (from a in db.Fish where a.GenusID == curc && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                                foreach (Fish x in curf)
                                {
                                    ds.Add(x);
                                }
                            }
                        }

                        break;
                    }
                case 4:
                    {
                        List<Fish> curf;
                        List<int> bo = (from o in db.Ordoes where o.OrdoName == txtname && o.Or_kiemduyet == true select o.OrdoID).ToList<int>();
                        foreach (int j in bo)
                        {
                            var ho = (from h in db.Familias where h.FamiliaID == j && h.Fa_kiemduyet == true select h.FamiliaID).ToList<int>();
                            foreach (int i in ho)
                            {
                                var chi = (from c in db.Genus where c.FamiliaID == i && c.Ge_kiemduyet == true select c.GenusID).ToList<int>();
                                foreach (int curc in chi)
                                {
                                    curf = new List<Fish>();
                                    curf = (from a in db.Fish where a.GenusID == curc && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                                    foreach (Fish x in curf)
                                    {
                                        ds.Add(x);
                                    }
                                }
                            }
                        }

                        break;
                    }
                case 5:
                    {
                        List<Fish> curf;
                        List<int> lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.ClassName == txtname select l.ClassID).ToList<int>();
                        foreach (int k in lop)
                        {
                            var bo = (from o in db.Ordoes where o.OrdoID == k && o.Or_kiemduyet == true select o.OrdoID).ToList<int>();
                            foreach (int j in bo)
                            {
                                var ho = (from h in db.Familias where h.FamiliaID == j && h.Fa_kiemduyet == true select h.FamiliaID).ToList<int>();
                                foreach (int i in ho)
                                {
                                    var chi = (from c in db.Genus where c.FamiliaID == i && c.Ge_kiemduyet == true select c.GenusID).ToList<int>();
                                    foreach (int curc in chi)
                                    {
                                        curf = new List<Fish>();
                                        curf = (from a in db.Fish where a.GenusID == curc && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                                        foreach (Fish x in curf)
                                        {
                                            ds.Add(x);
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                case 6:
                    {
                        List<Fish> curf;
                        List<int> nganh = (from ng in db.Phyla where ng.Ph_kiemduyet == true && ng.PhylumName == txtname select ng.PhylumID).ToList<int>();
                        foreach (int m in nganh)
                        {
                            var lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.ClassID == m select l.ClassID).ToList<int>();
                            foreach (int k in lop)
                            {
                                var bo = (from o in db.Ordoes where o.OrdoID == k && o.Or_kiemduyet == true select o.OrdoID).ToList<int>();
                                foreach (int j in bo)
                                {
                                    var ho = (from h in db.Familias where h.FamiliaID == j && h.Fa_kiemduyet == true select h.FamiliaID).ToList<int>();
                                    foreach (int i in ho)
                                    {
                                        var chi = (from c in db.Genus where c.FamiliaID == i && c.Ge_kiemduyet == true select c.GenusID).ToList<int>();
                                        foreach (int curc in chi)
                                        {
                                            curf = new List<Fish>();
                                            curf = (from a in db.Fish where a.GenusID == curc && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                                            foreach (Fish x in curf)
                                            {
                                                ds.Add(x);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }              
            }

                    string chuoi1 = " ";
                    foreach (Fish onefish in ds)
                    {
                        chuoi1 += "<tr>";
                        chuoi1 += "<td align=\"left\" width=\" 100px\" height=\"100px\">";
                        chuoi1 += "<img src=\"" + onefish.image + "\"/>";
                        chuoi1 += "</td>";
                        chuoi1 += "<td width=\"20px\"></td><td width=\"800px\"> <table><tr>";
                        chuoi1 += onefish.FishName + " " + onefish.Growth;
                        chuoi1 += "</p></tr><tr>";
                        chuoi1 += "<td align=\"center\"> <a href = \"/User/Information?id_fish=" + onefish.FishID + " \"> Xem thêm </a></td>";
                        chuoi1 += "</tr>";
                        chuoi1 += " </table>";
                        chuoi1 += "</td>";
                        chuoi1 += "</tr>";
                    }
                    ViewBag.View = chuoi1;

                    return View();
            }

        #endregion

        }
    }
